<template>
  <div class="index">
    <qyb-header></qyb-header>加入队伍
    <div>
      姓名：
      <input type="text" v-model="form.nickname" />
    </div>
    <div>
      职务：
      <select v-model="form.positionType">
        <option disabled value>请选择</option>
        <option value="1">队长</option>
        <option value="2">副队长</option>
        <option value="99">普通球员</option>
      </select>
    </div>
    <div @click="joinTeam">点击加入队伍</div>
    <pre>
      {{data}}
    </pre>
    <router-link :to="{name:'login'}">login</router-link>
  </div>
</template>
<script>
import Vue from "vue";
export default {
  data() {
    return {
      data: null,
      hehe: true,
      user: {
        lastName: "ggs"
      },
      form: {
        nickname: "",
        positionType: ""
      }
    };
  },
  watch: {
    $route() {
      // console.log('indexss');
    }
  },
  async mounted() {
    if (Cookies.get("passport") == undefined) {
      localStorage.setItem("url--join", window.location.href);
      this.$router.replace({
        name: "register"
      });
    }
    console.log(this.$route.query.teamId);
  },
  beforeRouteEnter(to, from, next) {
    console.log(to);
    console.log(Vue.$http);
    next(vm => {
      vm.haha();
    });
  },
  beforeRouteUpdate(to, from, next) {
    next();
  },
  methods: {
    haha() {
      console.log(2);
    },
    joinTeam() {
      this.$http
        .post(`/api/team/join/${this.$route.query.teamId}`, {
          ...this.form
        })
        .then(resp => {
          if (resp.status == 1) {
            alert("加入队伍成功");
            this.$router.push({
              name: "index"
            });
          }
        });
    },
    ceshi() {
      this.$router.push({
        name: this.$route.name,
        query: {
          hehe: +new Date()
        }
      });
    }
  }
};
</script>
<style lang="scss" scoped>
@import "./join.scss";
</style>